#include "key.h"

// 按键，外部中断
void KEY_Init(void)
{
    GPIO_InitTypeDef GPIO_InitStrue; // 
	
		EXTI_InitTypeDef EXTI_InitStruct; 
		NVIC_InitTypeDef NVIC_InitStruct; 
	
		RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE);
	
	
		GPIO_InitStrue.GPIO_Pin=GPIO_Pin_4; 
    GPIO_InitStrue.GPIO_Mode=GPIO_Mode_Out_PP; 
    GPIO_InitStrue.GPIO_Speed=GPIO_Speed_50MHz; 
    GPIO_Init(GPIOB,&GPIO_InitStrue); 
		
		
		GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource4); 
		EXTI_InitStruct.EXTI_Mode=EXTI_Mode_Interrupt; 
		EXTI_InitStruct.EXTI_Line=EXTI_Line4; 
		EXTI_InitStruct.EXTI_Trigger=EXTI_Trigger_Falling; 
		EXTI_InitStruct.EXTI_LineCmd=ENABLE; 
		EXTI_Init(&EXTI_InitStruct); 

		
		NVIC_InitStruct.NVIC_IRQChannel=EXTI4_IRQn; 
		NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority =0; 
		NVIC_InitStruct.NVIC_IRQChannelSubPriority =1; 
		NVIC_InitStruct.NVIC_IRQChannelCmd =ENABLE; 
		NVIC_Init(&NVIC_InitStruct);
}







